home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1388 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Function body banned in .H file - Can I still inline?
  5. Date: 10 Jan 1996 20:00:56 GMT
  6. Organization: Computer People Inc.
  7. Message-ID: <ALUN.CHAMPION.96Jan10150056@g7240065.bridge.bst.bls.com>
  8. References: <4d0ir0$68e@newsroom.hitc.com> <4d0u0a$gc7@news.cis.nctu.edu.tw>
  9. NNTP-Posting-Host: bstfirewall.bst.bls.com
  10. In-reply-to: terryt@mcs.com's message of 10 Jan 1996 17:45:46 GMT
  11.  
  12. In article <4d0u0a$gc7@news.cis.nctu.edu.tw> terryt@mcs.com (Terry Trippany) writes:
  13.  
  14. : In article <4d0ir0$68e@newsroom.hitc.com>, cruegger@eos.hitc.com says...
  15. :> 
  16. :> I am not permitted to put any function bodies into the .H file for a class.
  17. :> Question:
  18. :>   I would still like to make the small accessor routines inline. What
  19. :>   is my recourse, if any?
  20.  
  21. :   If you want to make a function inline without putting the source in the 
  22. : header then you can use the inline keyword.  BE AWARE that this is just a hint 
  23. The source still needs to be in the header if it is to be inlined in
  24. other translation units - see below.
  25.  
  26. : to the compiler and it may or may not treat it as inline depending on which 
  27. : compiler you use.
  28.  
  29. : eg: 
  30. : // file foo.hpp
  31.  
  32. : class Foo
  33. : {
  34. :   void myFunc();
  35. : }
  36.  
  37. : // file foo.cpp
  38.  
  39. : inline void Foo::myFunc() { ... }
  40.  
  41. : You could also specify the inline keyword in the declaration file if that's 
  42. : where you would like to put it.
  43.  
  44. This will only make the function inline - in that particular translation
  45. unit and not for the whole application.
  46.  
  47. [*excpert from standard*]
  48. 7.1.2 Function specifiers
  49. ...
  50. 3  An inline function shall be defined in every translation unit it is used
  51.    (3.2), and shall have exactly the same definition in every case (see one
  52.    definition rule, 3.2). ...
  53.  
  54. This basically says the function definition must be visible at compile time
  55. to be made inline and as such should probably best go into the header file
  56. to guarentee the same definition in every translation unit.
  57.  
  58. Regards
  59.  
  60.    -A.
  61.  
  62.  
  63.    
  64. -- 
  65. | A.Champion                |
  66.